define(function(require,exports,modlue){
	//var qdCommon = require('qd-common-1.0.0');
	var Ajax = require('extendModel/AjaxReturn');
	var Pager = require('commonPlugins/pager/pager');
	var typeVal = $("#type a.current").attr("data-val");
	var aprSearchVal = $("#aprSearch a.current").attr("data-val");
	var moneySearchVal = $("#moneySearch a.current").attr("data-val");
	var timeSearchVal = $("#timeSearch a.current").attr("data-val");
	var statusVal = $("#status a.current").attr("data-val");
	var orderVal = $("#order li.current a").attr("data-val");
	var nameVal = encodeURIComponent($("#name").val());
	var loading = "rows=6&type="+typeVal+"&aprSearch="+aprSearchVal+"&moneySearch="+moneySearchVal+"&timeSearch="+timeSearchVal+"&status="+statusVal+'&order='+orderVal+"&borrowName="+nameVal;


	ajaxUrl(loading);//初始化调用
	//排序
	$("#order li").click(function(){
		var val = parseInt($(this).find("a").attr("data-val"));
		if($(this).hasClass("current")){
			if(val > 0){
				val = 0 - val;
				$(this).find("a").attr("data-val",val);
				$(this).find("i").removeClass("descend").addClass("normal");
			}
			else if(val < 0)
			{
				val = 0-val;
				$(this).find("a").attr("data-val",val);
				$(this).find("i").removeClass("normal").addClass("descend");
			}
		}
		else{
			$(this).find("i").removeClass("normal").addClass("descend");
		}
		$(this).addClass("current").siblings().removeClass("current");
		var param = "type="+$("#type a.current").attr("data-val")+"&aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&status="+$("#status a.current").attr("data-val")+"&order="+val+"&borrowName="+encodeURIComponent($("#name").val());
		ajaxUrl(param);

	})
	
	//标种搜索
	$("#type a,#aprSearch a,#moneySearch a,#status a,#timeSearch a").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
		var param = getParam();
		ajaxUrl(param);
	});

	//点击搜索调用
	//$(".searchBtn").click(function(){
	//	var search = getParam();
	//	ajaxUrl(search);
	//});

	// 推荐的标
	// 投资列表页面-新手标
	// 首页-0元购
    var enjoy_option = {};
    enjoy_option.callBackFunction = function(){
        knobFcn();
    };
    /*Ajax.ajaxWithHandlebar("/indexBorrowInfo.html?type=deliverGoods", require("/themes/theme_default/media/tpl/home_zeroBuy.tpl"), $(".home_zeroBuy"),enjoy_option);
    //推荐表
    Ajax.ajaxWithHandlebar("/indexBorrowInfo.html?type=recommend", require("/themes/theme_default/media/tpl/home_deliver_invest.tpl"), $(".deliver_invest"),enjoy_option);
    // 投资列表页面-体验标
	Ajax.ajaxWithHandlebar("/indexBorrowInfo.html?type=experience", require("/themes/theme_default/media/tpl/home_experience_invest.tpl"), $(".taste_invest"),enjoy_option);
    
*/

	// 总排行
	Ajax.ajaxPacket("/index/rankList.html?rank=total","get", require("/themes/theme_default/media/tpl/invest/invest_rank.tpl"), $(".investI_rankC"));
	// 理财动态
	Ajax.ajaxPacket("/index/todayTenderList.html","get", require("/themes/theme_default/media/tpl/invest/today_tender.tpl"), $(".investI_dynC"));

	//获取过滤参数
	function getParam() {
		return "rows=6&type="+$("#type a.current").data("val")+"&aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&status="+$("#status a.current").attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&borrowName="+encodeURIComponent($("#name").val());
	}

	//通用显示函数
	function ajaxUrl(param) {

		Ajax.ajaxSimple('/invest/investJson.html?' + param + '&randomTime=' + (new Date()).getTime(), 'get', function (json) {
			//qdCommon.checkLogin(arguments[0]);
			//总记录数
			$(".quickBar span em").html(json.data.page.total);
			var tpl = require('../../tpl/investList.tpl');
			var template = Handlebars.compile(tpl);
			var html = template(json);
			$('.investListBox ul').html(html);
			knobFcn();
			//偶数行增加背景颜色
			//$(".investItem:odd").addClass("investItemBg");
			//分页插件
			if (json.data.page.pages > 0) {
				Pager.generPageHtml({
					pno: json.data.page.currentPage,//当前页码
					total: json.data.page.pages,//总页码
					totalRecords: json.data.page.total,//总数据条数
					isShowFirstPageBtn: false,
					isShowLastPageBtn: false,
					isShowTotalPage: false,
					isShowTotalRecords: false,
					isGoPage: false,
					lang: {
						prePageText: '上一页',
						nextPageText: '下一页'
					},
					mode: 'click',//click模式匹配getHref 和 click
					click: function (n, total, totalRecords) {
						Ajax.ajaxSimple("/invest/investJson.html?" + param + "&randomTime=" + (new Date()).getTime() + "&page=" + n, 'get', function (json) {

							var tpl = require('../../tpl/investList.tpl');
							var template = Handlebars.compile(tpl);
							var html = template(json);
							$('.investListBox ul').html(html);
							//偶数行增加背景颜色
							//$(".investItem:odd").addClass("investItemBg");
							//判断是否是IE浏览器
							//if (!+[1,]) require('/plugins/jquery.knob/excanvas');
							//不同的进度，更换成不同的颜色
							knobFcn();

						})

						this.selectPage(n); //处理完后可以手动条用selectPage进行页码选中切换
					}
				});;
			} else {
				$("#kkpager").html('暂无数据');
			}
		})
	}

	//翻页置顶
	require.async("commonJS/rollTo",function(){
		$("#kkpager").rollTo({
			oFinish: ".investList ", //要滚动到的元素
			sSpeed: "300",  //滚动速度
			bMonitor: false, //是否楼层监听
			sClass: "", //楼层监听时需要添加的样式
			iBias:-18,
			fnAdditional: "" //追加方法
		});
	})

	searchLiAlign();
	function searchLiAlign(){
		var lis = $(".investSearch li:visible");
		for(var j=0;j<5;j++){
			
			var width = 0;
			for(var i=0,len=lis.length;i<len;i++){
				if(lis.eq(i).find("a").length>j){
					var searchBtnWidth = lis.eq(i).find("a").eq(j).innerWidth();
					if(searchBtnWidth > width) 
						width = searchBtnWidth + 1;
				}
			}
			for(var i=0,len=lis.length;i<len;i++){
				if(lis.eq(i).find("a").length>j){
					lis.eq(i).find("a").eq(j).css("width",width);
				}
			}
		}
		
	}
	  /*S新手标圆形进度条*/
    require('/plugins/jquery.knob/jquery.knob.min');
    function knobFcn(){
    	$('.knob').each(function () {
    		var val = parseInt($(this).val());
    		if (val == 100) {
    			var isIE = function (ver) {
    				var b = document.createElement('b');
    				b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
    				return b.getElementsByTagName('i').length === 1;
    			};
    			if (isIE(8)) {
    				$(this).next().addClass("investComplete100");
    			}
    		}
    		$(this).attr("data-fgColor", "#da4453");
    	});
    	$('.knob').knob({
    		'thickness': .1,
    		'readOnly':true,
    		format: function(v) {
                return v+"%";
    		}

    	});
    }
    /*E新手标圆形进度条*/

});